package com.mbti.youmore.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mbti.youmore.entity.Coupon;
import com.mbti.youmore.mapper.UserMapper;
import com.mbti.youmore.service.CouponService;
import com.mbti.youmore.mapper.CouponMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Guqier
* @description 针对表【t_coupon】的数据库操作Service实现
* @createDate 2024-05-08 20:30:45
*/
@Service
public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon>
    implements CouponService{
    @Autowired
    private CouponMapper couponMapper;// 使用Spring自动注入工具类
    @Autowired
    private UserMapper userMapper;// 使用Spring自动注入工具类
    @Override
    public int saveCoupon(Coupon coupon) {
        int count=0;
        count=couponMapper.insert(coupon);
        return count;
    }

    @Override
    public List<Coupon> CouponList(int id) {
        return couponMapper.SerchCanCoupon(id);
    }

    @Override
    public int exchangeCoupon(Integer userId, Integer couponId) {
        Coupon coupon=couponMapper.selectById(couponId);
        int val=coupon.getCouponVal();
        int result=userMapper.updateIntegralthreeByUserId(userId,val);
        return result;
    }

    @Override
    public int insert(Integer userId, Integer couponId) {

        return couponMapper.addUC(userId,couponId);
    }

}




